package com.jdew.thkj.activity;

import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.jdew.thkj.R;
import com.jdew.thkj.adapter.MainFragmentPageAdapter;
import com.jdew.thkj.adapter.PddOrderAdapter;
import com.jdew.thkj.base.BaseActivity;
import com.jdew.thkj.base.BaseFragment;
import com.jdew.thkj.bean.PddOrderBean;
import com.jdew.thkj.fragment.FragmentFactory;
import com.jdew.thkj.fragment.JDOrderFragment;
import com.jdew.thkj.fragment.PDDOrderFragment;
import com.jdew.thkj.fragment.TBOrderFragment;
import com.jdew.thkj.view.NoScrollViewPager;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;

/**
 * Created by yangzai on 2018/5/27.
 */

public class OrderMingXiActivity extends BaseActivity {
    @Bind(R.id.back)
    ImageView back;
    @Bind(R.id.title)
    TextView title;
    @Bind(R.id.right)
    TextView right;
    @Bind(R.id.tb)
    CheckBox tb;
    @Bind(R.id.pdd)
    CheckBox pdd;
    @Bind(R.id.jd)
    CheckBox jd;
    @Bind(R.id.viewpager)
    NoScrollViewPager viewpager;
    public Dialog mWeiboDialog;
    public TBOrderFragment tbOrderFragment;
    public JDOrderFragment jdOrderFragment;
    public PDDOrderFragment pddOrderFragment;
    private List<Fragment> fragemnts;
    private MainFragmentPageAdapter madapter;

    @Override
    public int bindLayout() {
        return R.layout.activity_mingxi;
    }

    @Override
    public void initView(View view) {
        back.setVisibility(View.VISIBLE);
        right.setVisibility(View.VISIBLE);
        sp = getSharedPreferences("user", Activity.MODE_PRIVATE);
        editor = sp.edit();
        fragemnts = new ArrayList<>();
        tbOrderFragment = new TBOrderFragment();
        jdOrderFragment = new JDOrderFragment();
        pddOrderFragment = new PDDOrderFragment();
        fragemnts.add(tbOrderFragment);
        fragemnts.add(jdOrderFragment);
        fragemnts.add(pddOrderFragment);
        //实例化适配器
        madapter = new MainFragmentPageAdapter(getSupportFragmentManager(), fragemnts);
        //设置适配器
        viewpager.setAdapter(madapter);
        viewpager.setNoScroll(true);
        right.setText("订单查询");
        title.setText("订单明细");
        back.setOnClickListener(this);
        right.setOnClickListener(this);
        tb.setOnClickListener(this);
        jd.setOnClickListener(this);
        pdd.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.back: {
                finish();
            }
            break;
            case R.id.right: {
                startActivity(OrderSearchActivity.class);
            }
            break;
            case R.id.tb: {
                tb.setChecked(true);
                pdd.setChecked(false);
                jd.setChecked(false);
                tb.setTextColor(getResources().getColor(R.color.color_ffffff));
                pdd.setTextColor(getResources().getColor(R.color.color_000000));
                jd.setTextColor(getResources().getColor(R.color.color_000000));
                viewpager.setCurrentItem(0);
            }
            break;
            case R.id.jd: {
                jd.setChecked(true);
                tb.setChecked(false);
                pdd.setChecked(false);
                tb.setTextColor(getResources().getColor(R.color.color_000000));
                jd.setTextColor(getResources().getColor(R.color.color_ffffff));
                pdd.setTextColor(getResources().getColor(R.color.color_000000));
                viewpager.setCurrentItem(1);
            }
            break;
            case R.id.pdd: {
                pdd.setChecked(true);
                tb.setChecked(false);
                jd.setChecked(false);
                tb.setTextColor(getResources().getColor(R.color.color_000000));
                jd.setTextColor(getResources().getColor(R.color.color_000000));
                pdd.setTextColor(getResources().getColor(R.color.color_ffffff));
                viewpager.setCurrentItem(2);
            }
            break;
            default:
                break;
        }
    }


    public void toDetail(String itemId) {
        Bundle b = new Bundle();
        b.putSerializable("itemId", itemId);
        startActivity(TbProductDetailActivity.class, b);
    }

    public void toJDDetail(String itemId) {
        Bundle b = new Bundle();
        b.putSerializable("itemId", itemId);
        startActivity(JDProductDetailActivity.class, b);
    }
}
